/* 
[
  { status: 'fulfilled', value: xxx },
  { status: 'rejected', reason: xxx }
]
 */

function myPromiseAllSettled(promises) {
  return new Promise((resolve, reject) => {
    let result = [];
    let i = 0;
    let promiseArray = Array.from(promises);
    if (promiseArray.length === 0) {
      resolve([]);
    }
    promiseArray.forEach((promise, index) => {
      Promise.resolve(promise)
        .then((value) => {
          result[index] = {
            status:'fulfilled',
            value:value
          };
          i++;
          if (i === promiseArray.length) {
            resolve(result);
          }
        })
        .catch((reason) => {
          result[index] = {
            status:'rejected',
            reason:reason
          };
          i++;
          if (i === promiseArray.length) {
            resolve(result);
          }
        });
    });
  });
}
